#!/usr/bin/env python3
from PIL import Image
import os

# 图标尺寸
sizes = {
    'icon-36-ldpi.png': 36,
    'icon-48-mdpi.png': 48,
    'icon-72-hdpi.png': 72,
    'icon-96-xhdpi.png': 96,
    'icon-144-xxhdpi.png': 144,
    'icon-192-xxxhdpi.png': 192,
}

# 源图标路径
source_icon = '记账本.png'
output_dir = 'mobile/res/icon/android'

print('📱 开始生成Android图标...')

# 打开源图标
try:
    img = Image.open(source_icon)
    print(f'✅ 源图标尺寸: {img.size}')
    
    # 如果是RGBA模式，保持；如果是RGB，转换为RGBA
    if img.mode != 'RGBA':
        img = img.convert('RGBA')
    
    # 生成各个尺寸
    for filename, size in sizes.items():
        output_path = os.path.join(output_dir, filename)
        resized = img.resize((size, size), Image.Resampling.LANCZOS)
        resized.save(output_path, 'PNG')
        print(f'✅ 生成 {filename} ({size}x{size})')
    
    # 也复制一份原图
    img.save(os.path.join(output_dir, 'icon-original.png'), 'PNG')
    print(f'✅ 保存原图 icon-original.png')
    
    print('🎉 所有图标生成完成！')
    
except Exception as e:
    print(f'❌ 错误: {e}')
